package com.mjh.zhujianju.service.base.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.livew.framework.base.service.impl.BaseServiceImpl;
import com.livew.framework.utils.XTListUtils;
import com.livew.framework.utils.XTStringUtils;
import com.mjh.zhujianju.dao.base.AreasMapper;
import com.mjh.zhujianju.model.base.AreasEO;
import com.mjh.zhujianju.service.base.AreasService;

@Service
public class AreasServiceImpl extends BaseServiceImpl<AreasEO> implements AreasService{

	@Resource
	private AreasMapper areasMapper;
	
	public AreasServiceImpl(AreasMapper areasMapper) {
		super(areasMapper);
	}

	@Override
	public List<AreasEO> getListByParentCode(String code) {
		List<AreasEO> list = areasMapper.selectListByParentCode(code);
		return list;
	}

	@Override
	public List<AreasEO> getListByCode(String code) {
		List<AreasEO> list = areasMapper.selectChildListByCode(code);
		return list;
	}

	@Override
	public Map<String, String> getMap(String provinceCode,String cityCode,String countyCode,String streetCode) {
		List<String> codes = new ArrayList<>();
		if(!XTStringUtils.isEmpty(provinceCode)) {
			codes.add(provinceCode);
		}
		if(!XTStringUtils.isEmpty(cityCode)) {
			codes.add(cityCode);
		}
		if(!XTStringUtils.isEmpty(countyCode)) {
			codes.add(countyCode);
		}
		if(!XTStringUtils.isEmpty(streetCode)) {
			codes.add(streetCode);
		}
		if(XTListUtils.isEmpty(codes)) {
			return null;
		}
		List<AreasEO> list = areasMapper.selectList(codes);
		if(XTListUtils.isEmpty(list)) {
			return null;
		}
		Map<String,String> map = new HashMap<>();
		for (AreasEO areasEO : list) {
			map.put(areasEO.getCode(), areasEO.getName());
		}
		return map;
	}

	@Override
	public List<AreasEO> getProvinceList() {
		List<AreasEO> list = this.areasMapper.selectProvinceList();
		return list;
	}

	@Override
	public List<AreasEO> getSiblingListByCode(String code) {
		List<AreasEO> list = areasMapper.selectSiblingListByCode(code);
		return list;
	}
}
